<template>
	<div class="login-box">
		<div class="login">
			<h1 class="title">XX酒庄</h1>
			<div class="inp put">
				<span>账号:</span><el-input v-model="user" placeholder="请输入用户名" class="inpu"></el-input>
			</div>
			<div class="inp pua">
				<span>密码:</span><el-input placeholder="请输入密码" v-model="pwd" show-password class="inpu"
					@keyup.enter.native="login"></el-input>

			</div>
			<button @click="login" class="dl">登录</button>
		</div>

	</div>
</template>

<script>

export default {
	data() {
		return {
			user: "",
			pwd: "",
			baseUrl: require("../assets/baseUrl.js").baseUrl
		}
	},
	methods: {
		login() {
			//sessionStorage.setItem("username","张三");
			if (this.user === "" || this.pwd === "") {
				this.$message({
					message: "用户名和密码不能为空",
					type: "error"
				})
			} else {
				this.$http.post(this.baseUrl + "admin/check", {
					adminAccount: this.user,
					adminPassword: this.pwd
				}).then(res => {

					if (res.data.code == 200) {

						if (res.data.data[0].adminRole == 2) {
							this.$router.replace('/gerenzhong')
						/* 	console.log("2门店"+res.data.data[0].adminRole) */
							if (!sessionStorage.getItem("adminId")) {
								this.$message({
									message: "登陆成功",
									type: "success"

								})
							}
						} else {
							/* console.log("1或0总店"+res.data.data[0].adminRole) */
						
							this.$router.replace('/homepage')
							if (!sessionStorage.getItem("adminId")) {
								this.$message({
									message: "登陆成功",
									type: "success"

								})
							}
						}


						// this.changeLoginaa(res.data.data[0].adminId)
						sessionStorage.setItem("adminName", res.data.data[0].adminName)
						sessionStorage.setItem("pwd", this.pwd)
						sessionStorage.setItem("username", this.user)
						sessionStorage.setItem("adminId", res.data.data[0].adminId)
						sessionStorage.setItem("adminRole", res.data.data[0].adminRole)
						sessionStorage.setItem("logStatu", res.data.data[0].logStatus)
						sessionStorage.setItem("iserIcon", res.data.data[0].iserIcon)
						sessionStorage.setItem("adminPhone", res.data.data[0].adminPhone)

					} else {
						this.$message({
							message: res.data.msg,
							type: "error"
						})
						this.user = ""
						this.pwd = ""
					}

				})
			}
		},
		//自动登录
		zidoong() {
			if (sessionStorage.getItem("pwd") || sessionStorage.getItem("username")) {
				this.user = sessionStorage.getItem("username")
				this.pwd = sessionStorage.getItem("pwd")
				this.login()
			}
		}

	},
	mounted() {
		/* 	this.changeLogin() */
		this.zidoong()
		// this.$http.post(this.baseUrl + "admin/changeLog", {
		// 		adminId: "2",
    //     logStatus: 0
    // }).then(res => {
    // });

	}

}
</script>
<style lang="less">
* {
	margin: 0;
	padding: 0;
}

.login-box {
	width: 100vw;
	height: 100vh;
	background: url("../assets/login.png");
	background-size: 100% 100%;
	display: flex;
	justify-content: center;
	align-items: center;

	.login {
		width: 600px;
		height: 430px;
		border: 1px solid #000;
		border-radius: 10px;
		position: relative;
		background: #fff;
		opacity: 0.7;
		position: relative;
	}

	.inp {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.inp span {
		width: 65px;
		height: 40px;
		text-align: center;
		line-height: 40px;
		color: #000;
		font-weight: 700;
	}

	.inp .el-input {
		width: 300px;
		border: 2px solid #000;
		border-radius: 5px;
		background: none;

	}

	input::placeholder {
		color: #666;
	}

	.put {
		position: absolute;
		bottom: 227px;
		left: 125px;
	}

	.pua {
		position: absolute;
		bottom: 162px;
		left: 125px;
	}

	.dl {
		width: 150px;
		height: 50px;
		font-size: 24px;
		font-weight: 700;
		color: #fefefe;
		background: #652013;
		border-radius: 25px;
		position: absolute;
		bottom: 52px;
		left: 38%;
	}

	.title {
		position: absolute;
		top: 70px;
		left: 38%;
	}
}</style>